package elsim.entities

import javax.print.attribute.standard.Destination;

import junit.framework.Assert;

import org.junit.Test;

class LiftTest{
  @Test
  public void testLiftSmoke() {
    Lift lift = new Lift(0)
    lift.direction = Direction.UP
  }

  void addPassengerWithDest(Lift lift, int dest) {
    lift.addPendingRequest(new Passenger("abc", dest))
  }

  @Test
  public void computeFinalDestination() {
    Lift lift = new Lift(0)
    lift.position = 5
    lift.addPassenger(new Passenger("sgzmd", 10))
    lift.addPassenger(new Passenger("sgzmd", 11))
    lift.addPassenger(new Passenger("sgzmd", 12))
    addPassengerWithDest(lift, 11)
    lift.direction = Direction.UP

    Assert.assertEquals(12, lift.computeFinalDestination())
  }

  @Test
  public void computeFinalDestination2() {
    Lift lift = new Lift(0)
    lift.position = 5
    lift.addPassenger(new Passenger("sgzmd", 10))
    lift.addPassenger(new Passenger("sgzmd", 11))
    lift.addPassenger(new Passenger("sgzmd", 12))
    addPassengerWithDest(lift, 13)
    lift.direction = Direction.UP

    Assert.assertEquals(13, lift.computeFinalDestination())
  }

  @Test
  public void computeFinalDestination3() {
    Lift lift = new Lift(0)
    lift.position = 25
    lift.addPassenger(new Passenger("sgzmd", 10))
    lift.addPassenger(new Passenger("sgzmd", 11))
    lift.addPassenger(new Passenger("sgzmd", 12))
    addPassengerWithDest(lift, 11)
    lift.direction = Direction.DOWN

    Assert.assertEquals(10, lift.computeFinalDestination())
  }

  @Test
  public void shouldStartMoving() {
    Lift lift = new Lift(0)
    lift.position = 10
    lift.addPendingRequest(new Passenger("sgzmd", 20, 10))
    lift.direction = Direction.STATIONARY

    Assert.assertTrue lift.shouldMoveToPendingPassenger()
    Assert.assertEquals Direction.UP, lift.direction
  }

  @Test
  public void shouldNotStartMoving() {
    Lift lift = new Lift(0)
    lift.position = 20
    lift.addPendingRequest(new Passenger("sgzmd", 20, 10))
    lift.direction = Direction.STATIONARY

    Assert.assertFalse lift.shouldMoveToPendingPassenger()
    Assert.assertEquals Direction.STATIONARY, lift.direction
  }

  @Test
  public void shouldLoadPassengers() {
    Lift lift = new Lift(0)
    lift.position = 20
    lift.addPendingRequest(new Passenger("sgzmd", 20, 10))
    lift.direction = Direction.DOWN

    Assert.assertTrue(lift.shouldLoadPassengers())
  }

  @Test
  public void shouldNotLoadPassengers() {
    Lift lift = new Lift(0)
    lift.position = 10
    lift.addPendingRequest(new Passenger("sgzmd", 20, 10))
    lift.direction = Direction.DOWN

    Assert.assertFalse(lift.shouldLoadPassengers())
  }
  
  @Test
  public void shouldUnLoadPassengers() {
    Lift lift = new Lift(0)
    lift.position = 10
    lift.addPassenger(new Passenger("sgzmd", 20, 10))
    lift.direction = Direction.DOWN

    Assert.assertTrue(lift.shouldLoadPassengers())
  }
  
  @Test
  public void shouldNotUnLoadPassengers() {
    Lift lift = new Lift(0)
    lift.position = 20
    lift.addPassenger(new Passenger("sgzmd", 20, 10))
    lift.direction = Direction.DOWN

    Assert.assertFalse(lift.shouldLoadPassengers())
  }
}
